<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
	<title>角色管理</title>
	
	<script>
	var datatable_content;
		$(document).ready(function() {
			//聚焦第一个输入框
			$("#testapi").click(function(){
				var json = "{\"ordeno\":\"SK21517310001\"}";
				alert(json);
				var dataObj=eval("("+json+")");//转换为json对象 
				
				$.post('${ctx}/api/v1/waybill/getStatus',json,function(data)
				{
					alert(data);
				}
				);
				/*$.ajax({
					type : 'post',
					url : '${ctx}/api/v1/waybill/getStatus',
					data : json,
					dataType : 'json',
					success : function(data) {
						alert(data);
					},
					error : function(data) {
						alert(data);
					}
				});*/
			});
			initTable();
		});
		function initTable(){
			datatable_content = $("#contentTable").dataTable({
			   "bServerSide":true,
	           "sAjaxSource":'${ctx}/role/page',
	           "fnServerData": callback,
	           "bFilter": false,
	           "bSort": false,
	           "sZeroRecords": "查询无记录！",
	           "bProcessing": true,
	           "oLanguage": {
	               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	            },
	             "aoColumns":[
	             	 {"mData": null},
	             	 {"mData": "roleintro"},
	             	 {"mData": "status"},
	             	 {"mData": null},
	             ],
	             "aoColumnDefs":[
	             	{"aTargets": [0],
		              "mRender": function (data, display, row) {
			        	 return "<a href=\"${ctx}/role/v2_update/"+row.id+"\">"+row.rolename+"</a>";
			           }
		            },
	             	{"aTargets": [2],
		              "mRender": function (data, display, row) {
			        	 return data == "1" ? "有效" : data == "0" ? "无效" : "";
			           }
		            },
	             	{"aTargets": [3],
		              "mRender": function (data, display, row) {
			        	 return "<a href=\"${ctx}/role/delete/"+row.id+"\">删除</a>";
			           }
		            },
	             ],
			});
		}
		
		function callback( sSource, aoData, fnCallback ) {
		 aoData.push( { "name": "search_LIKE_rolename", "value": $("#search_LIKE_rolename").val()});  
			 //查询参数
		   $.ajax({ 
		       "type": "post",
		       "contentType": "application/json", 
		       "url": sSource,    
		       "dataType": "json",   
		       "data": JSON.stringify(aoData),
		       "success": fnCallback  
		   });    
		}
		
		function query(){
			datatable_content.fnDestroy();
			initTable();
		}
	</script>
</head>

<body>
	<section class="content">
		<c:if test="${not empty message}">
			<div id="message" class="alert alert-success"><button data-dismiss="alert" class="close">×</button>${message}</div>
		</c:if>
		<div class="row">
			<div class="col-md-12">
			<div class="box box-solid box-primary">
			<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
			<form class="form-search" action="#">
			 	<label>角色名称：</label> <input type="text" name="search_LIKE_rolename" id="search_LIKE_rolename" class="input-medium" value="${param.search_LIKE_rolename}" onkeydown='if(event.keyCode==13) {query(); return false;}'> 
			    <button type="button" class="btn btn-info" onclick="query()">搜索</button>
			    <a class="btn btn-info" href="${ctx}/role/v2_create">创建角色</a>
		    </form>
	    </div>
	</div>
	</div>
	</div>
	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-primary">
				<div class="box-header"></div>
				<div class="box-body">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
			<th>角色名称</th>
			<th>角色描述</th>
			<th>状态</th>
			<shiro:hasPermission name="/role/delete">
				<th>管理</th>
			</shiro:hasPermission>
		</tr></thead>
		<tbody>
		</tbody>
	</table>
	
	<%-- <shiro:hasPermission name="/role/create">
	<div><a class="btn" href="${ctx}/role/v2_create">创建角色</a></div>
	<div><a id="testapi" class="btn" href="#">测试接口</a></div>
	</shiro:hasPermission> --%>
	</section>
	</div>
	</div>
	</div>
	</div>
</body>
</html>
